import { Body, Controller, Delete, Get, Post, Put, Query, UploadedFiles, UseInterceptors } from '@nestjs/common';
import { OutstandingStudentsService } from './outstanding_students.service';
import { FileFieldsInterceptor } from '@nestjs/platform-express';

@Controller('outstandingStudents')
export class OutstandingStudentsController {
    constructor(
        private readonly outstandingStudentsService: OutstandingStudentsService
    ) { }

    @Post('add')
    @UseInterceptors(FileFieldsInterceptor([{ name: 'photo', maxCount: 1 }]))
    add(@UploadedFiles() files: any, @Body() body: any) {
        return this.outstandingStudentsService.add(files, body);
    }

    @Delete('delete')
    delete(@Body() body: any) {
        return this.outstandingStudentsService.delete(body.id);
    }

    @Put('update')
    @UseInterceptors(FileFieldsInterceptor([{ name: 'photo', maxCount: 1 }]))
    update(@UploadedFiles() files: any, @Body() body: any) {
        return this.outstandingStudentsService.update(body.id, files, body);
    }

    @Get()
    index(@Query() query: any) {
        return this.outstandingStudentsService.findAll(query);
    }

    @Get('getStudentsByYear')
    getStudentsByYear(@Query() query: any) {
        return this.outstandingStudentsService.getStudentsByYear(query);
    }
}
